/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: app2022 - Ex8
 * <p>Powered by webrx On 2022-01-24 16:41:26
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex8 {
    public static void main(String[] args) throws IOException {
        var src = ImageIO.read(new File("office.jpg"));


        var w = 82;
        var h = 82;
        var i = new BufferedImage(w, h, 1);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        int x = 358;
        int y = 20;
        g.drawImage(src, 0, 0, w, h, x, y, x + w, y + h, null);

        g.dispose();
        //保存图像文件
        try {
            ImageIO.write(i, "jpg", new File("i.jpg"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //打开图像文件
        try {
            Runtime.getRuntime().exec("cmd /k start i.jpg");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
